package com.hiep.connect.client.view;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.HasKeyUpHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TextBox;
import com.hiep.connect.client.UiUtils;
import com.hiep.connect.client.presenter.LoginViewPresenter.LoginDisplay;

public class LoginView extends Composite implements LoginDisplay {

	private TextBox textBoxEmail;
	private PasswordTextBox passwordTextBox;
	Button buttonSignIn;
	Button buttonRegister;

	public LoginView() {

		// VerticalPanel verticalPanel = new VerticalPanel();
		// initWidget(verticalPanel);

		FlexTable flexTable = new FlexTable();
		flexTable.setCellSpacing(10);
		// verticalPanel.add(flexTable);
		flexTable.setSize("296px", "120px");

		SimplePanel logoPanel = UiUtils.getLogoPanel();
		flexTable.setWidget(0, 0, logoPanel);

		Label lblLoginToAccount = new Label("Sign in to your account");
		// lblLoginToAccount.setStyleName("gwt-Label-Login");
		flexTable.setWidget(1, 2, lblLoginToAccount);

		Label lblUsername = new Label("Email");
		lblUsername.setStyleName("gwt-Label-Login");
		flexTable.setWidget(2, 1, lblUsername);
		lblUsername.setWidth("73px");

		textBoxEmail = new TextBox();
		flexTable.setWidget(2, 2, textBoxEmail);
		textBoxEmail.setWidth("200px");

		Label lblPassword = new Label("Password");
		lblPassword.setStyleName("gwt-Label-Login");
		flexTable.setWidget(3, 1, lblPassword);

//		flexTable.getCellFormatter().setHorizontalAlignment(2, 1,
//				HasHorizontalAlignment.ALIGN_RIGHT);
//		flexTable.getCellFormatter().setHorizontalAlignment(3, 1,
//				HasHorizontalAlignment.ALIGN_RIGHT);

		passwordTextBox = new PasswordTextBox();
		flexTable.setWidget(3, 2, passwordTextBox);
		passwordTextBox.setWidth("200px");

		CheckBox chckbxRememberMeOn = new CheckBox(
				"Remember me on this computer");
		flexTable.setWidget(4, 2, chckbxRememberMeOn);

		buttonSignIn = new Button("Sign in");
		// flexTable.setWidget(10, 5, buttonSignIn);
		buttonSignIn.setSize("85px", "30px");

		buttonRegister = new Button("Register");
		buttonRegister.setSize("85px", "30px");

		HorizontalPanel buttonPanel = new HorizontalPanel();
		buttonPanel.setSpacing(15);
		buttonPanel.add(buttonSignIn);
		buttonPanel.add(buttonRegister);

		flexTable.setWidget(5, 2, buttonPanel);
		flexTable.setWidget(9, 2, UiUtils.getSouthPanel());

		DecoratorPanel empty = new DecoratorPanel();
		empty.setSize("120px", "320px");
		empty.setStylePrimaryName("hiep-Login");
		empty.add(flexTable);
		initWidget(empty);

	}

	@Override
	public HasClickHandlers getLoginButton() {
		// TODO Auto-generated method stub
		return buttonSignIn;
	}

	@Override
	public HasValue<String> getEmailAddress() {
		// TODO Auto-generated method stub
		return textBoxEmail;
	}

	@Override
	public HasValue<String> getPassword() {
		// TODO Auto-generated method stub
		return passwordTextBox;
	}

	@Override
	public HasClickHandlers getRegisterButton() {
		// TODO Auto-generated method stub
		return buttonRegister;
	}

	@Override
	public HasKeyUpHandlers getPasswordField() {
		// TODO Auto-generated method stub
		return passwordTextBox;
	}

}